using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDLFPOS
    {
        public DataRow Convert2DLFPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDLFPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DLFPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DLFPPKEY"] = " ".PadRight(0 ); 
         dwReturn["DLFPFELD1"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD2"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD3"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD4"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD5"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD6"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD7"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD8"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD9"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD10"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD11"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD12"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD13"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD14"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD15"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD16"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD17"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD18"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD19"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD20"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD21"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD22"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD23"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD24"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD25"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD26"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD27"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD28"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD29"] = " ".PadRight(60 ); 
         dwReturn["DLFPFELD30"] = " ".PadRight(60 ); 
         dwReturn["DLFPFILLER"] = " ".PadRight(44 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDLFPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDLFPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDLFPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDLFPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDLFPOS(dwLocal, ITXDBVERSION);
            }
            UpdateDLFPOS(dwLocal);
        }
        public void InsertDLFPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DLFPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDLFPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DLFPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DLFPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DLFPOS";
            Return = Result;
            return Return;
        }
        public void DeleteDLFPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DLFPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDLFPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DLFPOS SET "
                    +"DLFPMANDANT= :DLFPMANDANT,"
                    +"DLFPPKEY= :DLFPPKEY,"
                    +"DLFPFELD1= :DLFPFELD1,"
                    +"DLFPFELD2= :DLFPFELD2,"
                    +"DLFPFELD3= :DLFPFELD3,"
                    +"DLFPFELD4= :DLFPFELD4,"
                    +"DLFPFELD5= :DLFPFELD5,"
                    +"DLFPFELD6= :DLFPFELD6,"
                    +"DLFPFELD7= :DLFPFELD7,"
                    +"DLFPFELD8= :DLFPFELD8,"
                    +"DLFPFELD9= :DLFPFELD9,"
                    +"DLFPFELD10= :DLFPFELD10,"
                    +"DLFPFELD11= :DLFPFELD11,"
                    +"DLFPFELD12= :DLFPFELD12,"
                    +"DLFPFELD13= :DLFPFELD13,"
                    +"DLFPFELD14= :DLFPFELD14,"
                    +"DLFPFELD15= :DLFPFELD15,"
                    +"DLFPFELD16= :DLFPFELD16,"
                    +"DLFPFELD17= :DLFPFELD17,"
                    +"DLFPFELD18= :DLFPFELD18,"
                    +"DLFPFELD19= :DLFPFELD19,"
                    +"DLFPFELD20= :DLFPFELD20,"
                    +"DLFPFELD21= :DLFPFELD21,"
                    +"DLFPFELD22= :DLFPFELD22,"
                    +"DLFPFELD23= :DLFPFELD23,"
                    +"DLFPFELD24= :DLFPFELD24,"
                    +"DLFPFELD25= :DLFPFELD25,"
                    +"DLFPFELD26= :DLFPFELD26,"
                    +"DLFPFELD27= :DLFPFELD27,"
                    +"DLFPFELD28= :DLFPFELD28,"
                    +"DLFPFELD29= :DLFPFELD29,"
                    +"DLFPFELD30= :DLFPFELD30,"
                    +"DLFPFILLER= :DLFPFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DLFPMANDANT", OracleType.NVarChar).Value = dwData["DLFPMANDANT"].ToString(); 
          or1.Parameters.Add("DLFPPKEY", OracleType.NVarChar).Value = dwData["DLFPPKEY"].ToString(); 
          or1.Parameters.Add("DLFPFELD1", OracleType.NVarChar).Value = dwData["DLFPFELD1"].ToString(); 
          or1.Parameters.Add("DLFPFELD2", OracleType.NVarChar).Value = dwData["DLFPFELD2"].ToString(); 
          or1.Parameters.Add("DLFPFELD3", OracleType.NVarChar).Value = dwData["DLFPFELD3"].ToString(); 
          or1.Parameters.Add("DLFPFELD4", OracleType.NVarChar).Value = dwData["DLFPFELD4"].ToString(); 
          or1.Parameters.Add("DLFPFELD5", OracleType.NVarChar).Value = dwData["DLFPFELD5"].ToString(); 
          or1.Parameters.Add("DLFPFELD6", OracleType.NVarChar).Value = dwData["DLFPFELD6"].ToString(); 
          or1.Parameters.Add("DLFPFELD7", OracleType.NVarChar).Value = dwData["DLFPFELD7"].ToString(); 
          or1.Parameters.Add("DLFPFELD8", OracleType.NVarChar).Value = dwData["DLFPFELD8"].ToString(); 
          or1.Parameters.Add("DLFPFELD9", OracleType.NVarChar).Value = dwData["DLFPFELD9"].ToString(); 
          or1.Parameters.Add("DLFPFELD10", OracleType.NVarChar).Value = dwData["DLFPFELD10"].ToString(); 
          or1.Parameters.Add("DLFPFELD11", OracleType.NVarChar).Value = dwData["DLFPFELD11"].ToString(); 
          or1.Parameters.Add("DLFPFELD12", OracleType.NVarChar).Value = dwData["DLFPFELD12"].ToString(); 
          or1.Parameters.Add("DLFPFELD13", OracleType.NVarChar).Value = dwData["DLFPFELD13"].ToString(); 
          or1.Parameters.Add("DLFPFELD14", OracleType.NVarChar).Value = dwData["DLFPFELD14"].ToString(); 
          or1.Parameters.Add("DLFPFELD15", OracleType.NVarChar).Value = dwData["DLFPFELD15"].ToString(); 
          or1.Parameters.Add("DLFPFELD16", OracleType.NVarChar).Value = dwData["DLFPFELD16"].ToString(); 
          or1.Parameters.Add("DLFPFELD17", OracleType.NVarChar).Value = dwData["DLFPFELD17"].ToString(); 
          or1.Parameters.Add("DLFPFELD18", OracleType.NVarChar).Value = dwData["DLFPFELD18"].ToString(); 
          or1.Parameters.Add("DLFPFELD19", OracleType.NVarChar).Value = dwData["DLFPFELD19"].ToString(); 
          or1.Parameters.Add("DLFPFELD20", OracleType.NVarChar).Value = dwData["DLFPFELD20"].ToString(); 
          or1.Parameters.Add("DLFPFELD21", OracleType.NVarChar).Value = dwData["DLFPFELD21"].ToString(); 
          or1.Parameters.Add("DLFPFELD22", OracleType.NVarChar).Value = dwData["DLFPFELD22"].ToString(); 
          or1.Parameters.Add("DLFPFELD23", OracleType.NVarChar).Value = dwData["DLFPFELD23"].ToString(); 
          or1.Parameters.Add("DLFPFELD24", OracleType.NVarChar).Value = dwData["DLFPFELD24"].ToString(); 
          or1.Parameters.Add("DLFPFELD25", OracleType.NVarChar).Value = dwData["DLFPFELD25"].ToString(); 
          or1.Parameters.Add("DLFPFELD26", OracleType.NVarChar).Value = dwData["DLFPFELD26"].ToString(); 
          or1.Parameters.Add("DLFPFELD27", OracleType.NVarChar).Value = dwData["DLFPFELD27"].ToString(); 
          or1.Parameters.Add("DLFPFELD28", OracleType.NVarChar).Value = dwData["DLFPFELD28"].ToString(); 
          or1.Parameters.Add("DLFPFELD29", OracleType.NVarChar).Value = dwData["DLFPFELD29"].ToString(); 
          or1.Parameters.Add("DLFPFELD30", OracleType.NVarChar).Value = dwData["DLFPFELD30"].ToString(); 
          or1.Parameters.Add("DLFPFILLER", OracleType.NVarChar).Value = dwData["DLFPFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
